package com.starlink.model.excel.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSONObject;
import com.starlink.model.excel.MallBookDetailExcelDTO;
import com.starlink.model.excel.MallBookExcelDTO;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: zhouyuhang01
 * @Date: 2024/6/9 12:15
 * @Description: MallBookListener
 * @Version 1.0.0
 */
public class MallBookDetailListener extends AnalysisEventListener<Object> {
    private List<MallBookDetailExcelDTO> dataList = new ArrayList<>();
    @Override
    public void invoke(Object object, AnalysisContext analysisContext) {
        if (!ObjectUtils.isEmpty(object)) {
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(object));
            String mallBooksId = jsonObject.getString("0");
            Integer interest = jsonObject.getInteger("1");
            Integer quality = jsonObject.getInteger("2");
            Integer guide = jsonObject.getInteger("3");
            String description = jsonObject.getString("4");
            String introduction = jsonObject.getString("5");
            String harvest = jsonObject.getString("6");
            String ready = jsonObject.getString("7");
            String look = jsonObject.getString("8");
            String read = jsonObject.getString("9");
            MallBookDetailExcelDTO mallBookDetailExcelDTO = new MallBookDetailExcelDTO();
            mallBookDetailExcelDTO.setMallBooksId(mallBooksId);
            mallBookDetailExcelDTO.setInterest(interest);
            mallBookDetailExcelDTO.setQuality(quality);
            mallBookDetailExcelDTO.setGuide(guide);
            mallBookDetailExcelDTO.setDescription(description);
            mallBookDetailExcelDTO.setIntroduction(introduction);
            mallBookDetailExcelDTO.setHarvest(harvest);
            mallBookDetailExcelDTO.setReady(ready);
            mallBookDetailExcelDTO.setLook(look);
            mallBookDetailExcelDTO.setRead(read);
            dataList.add(mallBookDetailExcelDTO);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
    public List<MallBookDetailExcelDTO> getDataList() {
        return dataList;
    }
}
